<%@ page  contentType="text/html;" language="java" pageEncoding="UTF-8" %>
<%@ page import="java.util.*" %>
<HTML xmlns:stedysoft>
<HEAD>
<TITLE>Action Properties</TITLE>
<META NAME="Author" CONTENT="FengChun(f15_nsm@hotmail.com)">
<META NAME="Keywords" CONTENT="WebFlow">

		
<link rel="stylesheet" type="text/css" href="inc/style.css">
<link rel="stylesheet" type="text/css" href="inc/webTab/webtab.css">
<script language=jscript src="inc/function.js"></script>
<script language=jscript src="inc/shiftlang.js"></script>
<script language=jscript src="inc/webTab/webTab.js"></script>

<style> 
body {
	background-color: buttonface;
	scroll: no;
	margin: 7px, 0px, 0px, 7px;
	border: none;
	overflow: hidden;	

}
</style>

<SCRIPT LANGUAGE="JavaScript">
<!--
function iniWindow(){
   var opener = window.dialogArguments;
   var url = opener.dialogURL;
   var actionId = url.indexOf('?actionid=')<0?'':url.slice(url.indexOf('?actionid=')+10,url.length);
   
   try{
     if(opener.LANG!='') shiftLanguage(opener.LANG,"actiondialog");

     var FlowXML = opener.document.all.FlowXML;		 

     if(FlowXML.value!=''){
	     iniActionDialog(FlowXML,actionId);
	 }else{
	     alert('打开动作属性对话框时出错！');
		 window.close();  
	 }	 
   }catch(e){
     alert('打开动作属性对话框时出错！');
	 window.close();
   }   
}

function iniActionDialog(FlowXML,actionId){
   
   xmlDoc = new ActiveXObject('MSXML2.DOMDocument');
   xmlDoc.async = false;
   xmlDoc.loadXML(FlowXML.value);
   
   var xmlRoot = xmlDoc.documentElement;
   var Actions = xmlRoot.getElementsByTagName("Actions").item(0);
   var fromStep = '',toStep = '';
   for ( var i = 0;i < Actions.childNodes.length;i++ ){
      Action = Actions.childNodes.item(i);
	  id = Action.getElementsByTagName("BaseProperties").item(0).getAttribute("id");
	  if(id==actionId){
	    fromStep = Action.getElementsByTagName("BaseProperties").item(0).getAttribute("from");
		toStep = Action.getElementsByTagName("BaseProperties").item(0).getAttribute("to");

		document.all.ActionId.value = actionId;
    	document.all.ActionText.value = Action.getElementsByTagName("BaseProperties").item(0).getAttribute("text");
		setRadioGroupValue(document.all.ActionType,Action.getElementsByTagName("BaseProperties").item(0).getAttribute("actionType"));  
		
		document.all.StartArrow.value = Action.getElementsByTagName("VMLProperties").item(0).getAttribute("startArrow");
		document.all.EndArrow.value = Action.getElementsByTagName("VMLProperties").item(0).getAttribute("endArrow");
		document.all.StrokeWeight.value = Action.getElementsByTagName("VMLProperties").item(0).getAttribute("strokeWeight");
	  }
   }

   var Steps = xmlRoot.getElementsByTagName("Steps").item(0);
   var from = document.all.From;
   var to = document.all.To;
   for ( var i = 0;i < Steps.childNodes.length;i++ ) {
      Step = Steps.childNodes.item(i);
	  id = Step.getElementsByTagName("BaseProperties").item(0).getAttribute("id");
	  var stype = Step.getElementsByTagName("BaseProperties").item(0).getAttribute("stepType");
	  text = Step.getElementsByTagName("BaseProperties").item(0).getAttribute("text");

	  fromSelected = fromStep==id?true:false;
	  toSelected = toStep==id?true:false;
	  if(stype!='EndStep') addSelectOption(from,text,id,fromSelected);
	  if(stype!='BeginStep') addSelectOption(to,text,id,toSelected);	  
   } 
}

function okOnClick(){
   var opener = window.dialogArguments;
   var url = opener.dialogURL;
   var actionId = url.indexOf('?actionid=')<0?'':url.slice(url.indexOf('?actionid=')+10,url.length);
   
   try{
     var FlowXML = opener.document.all.FlowXML;

	 xml = getActionXML(FlowXML,actionId);
	 if(xml!='') {
	   FlowXML.value = xml;
	   window.close();
	 }
    }catch(e){
     alert('关闭动作属性对话框时出错！');
	 window.close();
   }   
}
function cancelOnClick(){
   window.close();
}
function applyOnClick(){
   var opener = window.dialogArguments;
   var url = opener.dialogURL;
   var actionId = url.indexOf('?actionid=')<0?'':url.slice(url.indexOf('?actionid=')+10,url.length);

   try{
     var FlowXML = opener.document.all.FlowXML;

	 xml = getActionXML(FlowXML,actionId);
	 if(xml!='') {
	   FlowXML.value = xml;
	   btnApply.disabled=true;
	 }
   }catch(e){
     alert('关闭动作属性对话框时出错！');
	 window.close();
   }   
}

function getActionXML(FlowXML,actionId){
  id = document.all.ActionId.value;
  text = document.all.ActionText.value;
  actionType = getRadioGroupValue(document.all.ActionType);  
  from = getSelectValue(document.all.From);
  to = getSelectValue(document.all.To);

  
  
  if(id=='') {alert('请先填写动作编号！');return '';}
  if(text=='') {alert('请先填写动作名称！');return '';}
  if(from=='' || to=='') {alert('请先选择起始步骤和目的步骤！');return '';}

  startArrow = document.all.StartArrow.value;
  endArrow = document.all.EndArrow.value;
  strokeWeight = document.all.StrokeWeight.value;
  var xml = ""; 

  xml+= '<Action><BaseProperties id="'+id+'" text="'+text+'" actionType="'+actionType+'" from="'+from+'" to="'+to+'" />';
  xml+= '<VMLProperties startArrow="'+startArrow+'" endArrow="'+endArrow+'" strokeWeight="'+strokeWeight+'" zIndex="" />';
  xml+= '<FlowProperties /></Action>';
    
  var xmlDoc = new ActiveXObject('MSXML2.DOMDocument');
  xmlDoc.async = false;
  xmlDoc.loadXML(FlowXML.value);
  var xmlRoot = xmlDoc.documentElement;
  var Actions = xmlRoot.getElementsByTagName("Actions").item(0);
  var Steps = xmlRoot.getElementsByTagName("Steps").item(0);

  for ( var i = 0;i < Actions.childNodes.length;i++ ) {
      Action = Actions.childNodes.item(i);
	  lId = Action.getElementsByTagName("BaseProperties").item(0).getAttribute("id");

	   if(lId==id && actionId=='') {
	    alert('新动作编号已存在！请重新输入！');return '';
	  }
	  if(lId==actionId && actionId!='') {
	    Actions.removeChild(Action);break;    
	  }	  
  }
  
   /*
   for ( var i = 0;i < Actions.childNodes.length;i++ ) {
      Action = Actions.childNodes.item(i);
	  lId = Action.getElementsByTagName("BaseProperties").item(0).getAttribute("id");	  
	  for ( var i = 0;i < Steps.childNodes.length;i++ ) {
      Step = Steps.childNodes.item(i);
	  nId = Step.getElementsByTagName("BaseProperties").item(0).getAttribute("id");
	  
	  if(nId==id) {
	    alert('新动作编号已被占用！请重新输入！\n\nThis Action Id has exist! Please input non-repeat Step Id!');return '';
	  }	  
    }
    
  }
  */
   var pc=0;

  for ( var j = 0;j < Actions.childNodes.length;j++ ) {
      Action = Actions.childNodes.item(j); 
	  lfrom = Action.getElementsByTagName("BaseProperties").item(0).getAttribute("from");
	  //alert("lfrom"+lfrom);
	  lto = Action.getElementsByTagName("BaseProperties").item(0).getAttribute("to");
	  
	  
	  if(lfrom==from && lto==to) {
	   alert('该关系已存在！请重新输入！');return '';
	  }
	  if(lfrom==to && lto==from) {
	    alert('该关系已存在！请重新输入！');return '';
	  }
	  
	  if(lfrom==from){
	    pc++;
	    break;
	  }
  }

if(pc>0){
	var pcName=getSelectText(document.all.From);
    alert("请输入节点'"+pcName+"'各子结点的分支条件！");
  /*for ( var j = 0;j < Actions.childNodes.length;j++ ) {
      Action = Actions.childNodes.item(j); 
	  lfrom = Action.getElementsByTagName("BaseProperties").item(0).getAttribute("from");
	  //alert("lfrom"+lfrom);
	  lto = Action.getElementsByTagName("BaseProperties").item(0).getAttribute("to");
	  
	  //var pId = an.getElementsByTagName("BaseProperties").item(0).getAttribute("from");
       if(from!=lto && lfrom==from){
	    pc++;
	    //kk=0;
	    break;
	　   }
  }*/
  
}  
  
  var xmlDoc2 = new ActiveXObject('MSXML2.DOMDocument');
  xmlDoc2.async = false;
  xmlDoc2.loadXML(xml);     
  Actions.appendChild(xmlDoc2.documentElement); 
  
  return xmlRoot.xml;
}
//-->
</SCRIPT> 

</HEAD>

<BODY onload='iniWindow()' onunload=''>
<table border="0" cellpadding="0" cellspacing="0" height=385px>
<thead>
  <tr id="WebTab">
	<td class="selectedtab" id="tab1" onmouseover='hoverTab("tab1")' onclick="switchTab('tab1','contents1');"><span id=tabpage1>基本属性</span></td>
	<td class="tab" id="tab2" onmouseover='hoverTab("tab2")' onclick="switchTab('tab2','contents2');"><span id=tabpage2>图表属性</span></td>	
	<td class="tabspacer" width=400>&nbsp;</td>	
  </tr>
</thead>
<tbody>
  <tr>
	<td id="contentscell" colspan="5">
<!-- Tab Page 1 Content Begin -->
<div class="selectedcontents" id="contents1">
<TABLE border=0 width="100%" height="100%">
<TR valign=top>
	<TD></TD>
	<TD width="100%" valign=top>
	<Fieldset style="border: 1px solid #C0C0C0;">
	<LEGEND align=left style="font-size:9pt;">&nbsp;<span id=tabpage1_1>基本属性</span>&nbsp;</LEGEND>
	<TABLE border=0 width="100%" height="100%" style="font-size:9pt;">	
	<TR valign=top>
		<TD width=5></TD>
		<TD><span id=tabpage1_2>动作编号</span>&nbsp;&nbsp;<INPUT TYPE="text" NAME="ActionId" value="newaction" class=txtput></TD>
		<TD></TD>
	</TR>
	<TR valign=top> 
		<TD></TD>
		<TD><span id=tabpage1_3>动作名称</span>&nbsp;&nbsp;<INPUT TYPE="text" NAME="ActionText" value="" class=txtput></TD>
		<TD></TD>
    </TR>
	<TR valign=top style="{display: 'none'}">
		<TD></TD>
		<TD><span id=tabpage1_4>线段类型</span>&nbsp;&nbsp;<FONT style="font-size:10pt;" COLOR="#919CD0"><INPUT TYPE="radio" NAME="ActionType" value="PolyLine" checked disabled><span id=tabpage1_5 style="{color:#000}">折线</span>&nbsp;<INPUT TYPE="radio" NAME="ActionType" value="Line" disabled><span id=tabpage1_6 style="{color:#000}">直线</span>&nbsp;</FONT></TD>
		<TD></TD>
    </TR>
	<TR valign=top>
		<TD width=5></TD>
		<TD><span id=tabpage1_7>起始步骤</span>&nbsp;&nbsp;<SELECT NAME="From" class=txtput></SELECT></TD>
		<TD></TD>
	</TR>
	<TR valign=top>
		<TD></TD>
		<TD><span id=tabpage1_8>目的步骤</span>&nbsp;&nbsp;<SELECT NAME="To" class=txtput></SELECT></TD>
		<TD></TD>
    </TR>
	<TR height="3">
		<TD></TD>
		<TD></TD>
		<TD></TD>
	</TR>
	</TABLE>
	</Fieldset>
	</TD>
	<TD>&nbsp;</TD>
</TR>

<TR height="100%">
	<TD></TD><TD></TD><TD></TD>
</TR> 
</TABLE>
</div>
<!-- Tab Page 1 Content End -->

<!-- Tab Page 2 Content Begin -->
<div class="contents" id="contents2">
<TABLE border=0 width="100%" height="100%">
<TR valign=top>
	<TD></TD>
	<TD width="100%" valign=top>
	<Fieldset style="border: 1px solid #C0C0C0;">
	<LEGEND align=left style="font-size:9pt;">&nbsp;<span id=tabpage2_1>动作样式</span>&nbsp;</LEGEND>
	<TABLE border=0 width="100%" height="100%" style="font-size:9pt;">	
	<TR valign=top>
		<TD width=5></TD>
		<TD><span id=tabpage2_2>开始箭头</span>&nbsp;&nbsp;<INPUT TYPE="text" NAME="StartArrow" value="" class=txtput></TD>
		<TD></TD>
	</TR>
	<TR valign=top>
		<TD width=5></TD>
		<TD><span id=tabpage2_3>结束箭头</span>&nbsp;&nbsp;<INPUT TYPE="text" NAME="EndArrow" value="Classic" class=txtput></TD>
		<TD></TD>
	</TR>
	<TR valign=top>
		<TD></TD>
		<TD><span id=tabpage2_4>线条粗细</span>&nbsp;&nbsp;<INPUT TYPE="text" NAME="StrokeWeight" value="" class=txtput></TD>
		<TD></TD>
    </TR>	
	<TR height="3">
		<TD></TD>
		<TD></TD>
		<TD></TD>
	</TR>
	</TABLE>
	</Fieldset>
	</TD>
	<TD>&nbsp;</TD>
</TR>

<TR height="100%">
	<TD></TD><TD></TD><TD></TD>
</TR>
</TABLE>  
</div>
<!-- Tab Page 2 Content End -->


	</td>
  </tr>
</tbody>
</table>  

<table cellspacing="1" cellpadding="0" border="0" style="position: absolute; top: 400px; left: 0px;">
	<tr>
		<td width="100%"></td>
		<td><input type=button id="btnOk" class=btn value="确 定" onclick="jscript: okOnClick();">&nbsp;&nbsp;&nbsp;</td>
		<td><input type=button id="btnCancel" class=btn value="取 消" onclick="jscript: cancelOnClick();">&nbsp;&nbsp;&nbsp;</td>
		<td><input type=button id="btnApply" class=btn value="应 用" onclick="jscript: okOnClick();">&nbsp;&nbsp;&nbsp;</td>
	</tr>
</table>
</BODY>
</HTML>
